package main.chapter3.dataclass

data class Country(var id: Int, var name: String)

class ComponentX {
    operator fun component1(): String {
        return "Hello"
    }

    operator fun component2(): Int {
        return 2
    }

    operator fun component3(): Double {
        return 3.0
    }
}

fun main(args: Array<String>) {
    val china = Country(1, "中国")
    println(china)

    println(china.component1()) //id
    println(china.component2()) //name

    //data class中实现了componentN的方法
    val (id, name) = china
    println("id is $id, name is $name")

    val componentX = ComponentX()
    //这种赋值方式是使用component来实现的
    val (a, b, c) = componentX
    println("a=$a,b=$b,c=$c")
}